package project;

public class ModifiedQuickSort {
	public int[] numbers;
	public int number;
	public String[] array;

	public void sort(int[] requency, String[] array) {

		if (requency == null || requency.length == 0) {
			return;
		}
		this.numbers = requency;
		number = requency.length;
		this.array = array;
		quicksort(0, number - 1);
	}

	private void quicksort(int low, int high) {
		int i = low, j = high;
		int pivot = numbers[low + (high - low) / 2];

		while (i <= j) {
			while (numbers[i] < pivot) {
				i++;
			}
			while (numbers[j] > pivot) {
				j--;
			}

			if (i <= j) {
				exchange(i, j);
				i++;
				j--;
			}
		}
		if (low < j)
			quicksort(low, j);
		if (i < high)
			quicksort(i, high);
	}

	private void exchange(int i, int j) {
		int temp = numbers[i];
		numbers[i] = numbers[j];
		numbers[j] = temp;

		String temp2 = array[i];
		array[i] = array[j];
		array[j] = temp2;
	}
}
